package com.ruoyi.yzchu.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.yzchu.domain.YzcComment;
import com.ruoyi.yzchu.service.IYzcCommentService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 文章评论（树状结构）Controller
 * 
 * @author ruoyi
 * @date 2025-04-06
 */
@RestController
@RequestMapping("/system/comment")
public class YzcCommentController extends BaseController
{
    @Autowired
    private IYzcCommentService yzcCommentService;

    /**
     * 查询文章评论（树状结构）列表
     */
    @PreAuthorize("@ss.hasPermi('system:comment:list')")
    @GetMapping("/list")
    public AjaxResult list(YzcComment yzcComment)
    {
        List<YzcComment> list = yzcCommentService.selectYzcCommentList(yzcComment);
        return success(list);
    }

    /**
     * 导出文章评论（树状结构）列表
     */
    @PreAuthorize("@ss.hasPermi('system:comment:export')")
    @Log(title = "文章评论（树状结构）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YzcComment yzcComment)
    {
        List<YzcComment> list = yzcCommentService.selectYzcCommentList(yzcComment);
        ExcelUtil<YzcComment> util = new ExcelUtil<YzcComment>(YzcComment.class);
        util.exportExcel(response, list, "文章评论（树状结构）数据");
    }

    /**
     * 获取文章评论（树状结构）详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:comment:query')")
    @GetMapping(value = "/{commentId}")
    public AjaxResult getInfo(@PathVariable("commentId") Long commentId)
    {
        return success(yzcCommentService.selectYzcCommentByCommentId(commentId));
    }

    /**
     * 新增文章评论（树状结构）
     */
    @PreAuthorize("@ss.hasPermi('system:comment:add')")
    @Log(title = "文章评论（树状结构）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YzcComment yzcComment)
    {
        return toAjax(yzcCommentService.insertYzcComment(yzcComment));
    }

    /**
     * 修改文章评论（树状结构）
     */
    @PreAuthorize("@ss.hasPermi('system:comment:edit')")
    @Log(title = "文章评论（树状结构）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YzcComment yzcComment)
    {
        return toAjax(yzcCommentService.updateYzcComment(yzcComment));
    }

    /**
     * 删除文章评论（树状结构）
     */
    @PreAuthorize("@ss.hasPermi('system:comment:remove')")
    @Log(title = "文章评论（树状结构）", businessType = BusinessType.DELETE)
	@DeleteMapping("/{commentIds}")
    public AjaxResult remove(@PathVariable Long[] commentIds)
    {
        return toAjax(yzcCommentService.deleteYzcCommentByCommentIds(commentIds));
    }
}
